package com.yehun.config;

import com.yehun.service.RouteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * 初始化项目
 */
@Component
public class InitializeHandler implements ApplicationListener<ContextRefreshedEvent> {

    private static final Logger logger = LoggerFactory.getLogger(InitializeHandler.class);

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if (event.getApplicationContext().getParent() == null) { //root application context
            logger.info("yehun-cms route initialize begin...");
            event.getApplicationContext().getBean(RouteService.class).initialize();
            //AbstractHandlerMethodMapping<RequestMappingInfo> handlerMapping = event.getApplicationContext().getBean(RequestMappingHandlerMapping.class);
            //Map<RequestMappingInfo, HandlerMethod> map = handlerMapping.getHandlerMethods();
            //for(RequestMappingInfo info : map.keySet()){
            //    logger.info("{},{}", info.getPatternsCondition().toString(), map.get(info).getBean().toString());
            //}
            logger.info("yehun-cms route initialize end...");
        }
    }

}